package com.hpin.mlxteacher.child;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.hpin.mlxteacher.R;
import com.hpin.mlxteacher.adapter.HistoryAdapter;
import com.hpin.mlxteacher.base.BaseActivity;

import java.util.Calendar;

/**
 * 个人历史考勤记录页面
 * Created by Aaron on 2015/7/28.
 */
public class SingleHistoryActivity extends BaseActivity {

    private String name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_single_history);
        name = getIntent().getStringExtra("name");

        initWidget();

    }

    private void initWidget() {

        ImageView iv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);
        TextView tv_right = (TextView) findViewById(R.id.tv_right);

        tv_title.setText(name);
        tv_right.setText(getResources().getString(R.string.choose_date));

        TextView tv_date = (TextView) findViewById(R.id.tv_date);
        TextView tv_am = (TextView) findViewById(R.id.tv_am);
        TextView tv_noon = (TextView) findViewById(R.id.tv_noon);
        TextView tv_pm = (TextView) findViewById(R.id.tv_pm);
        ListView lv_details = (ListView) findViewById(R.id.lv_details);

        HistoryAdapter adapter = new HistoryAdapter(this);
        lv_details.setAdapter(adapter);

        iv_left.setOnClickListener(this);
        tv_right.setOnClickListener(this);

    }

    @Override
    public void widgetClick(View v) {
        switch (v.getId()) {
            case R.id.iv_left:
                finish();
                break;

            case R.id.tv_right://选择日期

                Calendar c = Calendar.getInstance();

                new DatePickerDialog(SingleHistoryActivity.this, new OnDateSetListener() {

                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear,
                                          int dayOfMonth) {
                        // TODO Auto-generated method stub
                        Toast.makeText(SingleHistoryActivity.this, year + "year " + (monthOfYear + 1) + "month " + dayOfMonth + "day", Toast.LENGTH_SHORT).show();
                    }


                }, c.get(Calendar.YEAR), c.get(Calendar.MONTH),
                        c.get(Calendar.DAY_OF_MONTH)).show();
                break;

        }
    }
}
